package pers.course.week9;

import java.util.*;

public class TraverseNumber{
    public static void arrayListTraverse(List<Integer> list) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == 5) {
                System.out.println(list.get(i));
            } else {
                System.out.print(list.get(i) + " ");
            }
        }
        for (Integer integer : list) {
            if (integer == 5) {
                System.out.println(integer);
            } else {
                System.out.print(integer + " ");
            }
        }
        Iterator<Integer> iter = list.listIterator();
        while (iter.hasNext()) {
            int n = iter.next();
            if (n == 5) {
                System.out.println(5);
            } else {
                System.out.print(n + " ");
            }
        }
    }
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        Scanner in = new Scanner(System.in);
        for (int i = 1; i <= 5; i++) {
            list.add(i);
        }
        arrayListTraverse(list);
    }
}
